﻿layui.config({
    base: '/Lib/layui/extend/'
}).extend({
    formSelects: 'formSelects-v4'
}).use(['form', 'layedit', 'layer', 'laydate', 'jquery'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        player = parent.layer || layui.layer,
        laydate = layui.laydate;

    var salaryPaymentSubsidyLogic = {
        //初始化
        init: function () {

            self = this;

            this.Parameters = {
                saveUrl: "/Staff/SalaryPayment/SaveSubsidy"
            };

            this.initPage();

            this.bindEvent();

        },
        //初始化列表
        initPage: function () {

            //获取信息
            var data = GrdLayUI.getUrlParameters();
            self.logicFunc.loadInfo(data);
            form.render();

        },
        //绑定事件
        bindEvent: function () {

            //监听提交
            form.on('submit(modifyButton)', self.logicFunc.saveInfo);

            //关闭
            $("#btnClose").on("click", self.logicFunc.close);

        },
        //逻辑方法
        logicFunc: {

           /**
            * 获取修改的信息
            * @param {any} data
            */
            loadInfo: function (data) {
                GrdLayUI.assignmentData("#modify-form", data);
            },
            //保存数据
            saveInfo: function () {

                var modifyInfo = GrdLayUI.initParamsData($("#modify-form"));
                var json = {
                    parameters: modifyInfo
                }
                GrdLayUI.ajaxPost({
                    url: self.Parameters.saveUrl,
                    data: json,
                    success: function (result) {
                        if (result.Code == 1000) {

                            GrdLayUI.msg(result.Msg, "成功", function () {
                                //获取窗口索引
                                var index = player.getFrameIndex(window.name);
                                //关闭子页面
                                player.close(index);
                                //刷新父页面
                                window.parent.location.reload();
                            });

                        } else {
                            GrdLayUI.msg(result.Msg, "警告");
                        }
                    }
                });
            },
            //取消
            close: function () {
                player.closeAll();
            }
        },
        //工具
        tools: {
        }
    };
    salaryPaymentSubsidyLogic.init();
});
